﻿package core.image
{
    import flash.filters.*;

    public class ConvolutionMatrix extends Object
    {
        var matrix:Array;
        var cf:ConvolutionFilter;

        public function ConvolutionMatrix()
        {
            this.cf = new ConvolutionFilter();
            return;
        }// end function

        public function HighPass() : void
        {
            this.matrix = [-1, -1, -1, -1, 9, -1, -1, -1, -1];
            this.cf.matrixX = 3;
            this.cf.matrixY = 3;
            this.cf.matrix = this.matrix;
            return;
        }// end function

        public function Engrave() : void
        {
            this.matrix = [1, 1, 1, 0, 1, 0, -1, -1, -1];
            this.cf.matrixX = 3;
            this.cf.matrixY = 3;
            this.cf.matrix = this.matrix;
            return;
        }// end function

        public function Sharpen() : void
        {
            this.matrix = [0, -0.5, 0, -0.5, 3, -0.5, 0, -0.5, 0];
            this.cf.matrixX = 3;
            this.cf.matrixY = 3;
            this.cf.matrix = this.matrix;
            return;
        }// end function

        public function Blur() : void
        {
            this.matrix = [0, 1, 0, 1, 1, 1, 0, 1, 0];
            this.cf.matrixX = 3;
            this.cf.matrixY = 3;
            this.cf.divisor = 5;
            this.cf.matrix = this.matrix;
            return;
        }// end function

        public function Emboss() : void
        {
            this.matrix = [-2, -1, 0, -1, 1, 1, 0, 1, 2];
            this.cf.matrixX = 3;
            this.cf.matrixY = 3;
            this.cf.divisor = 1;
            this.cf.matrix = this.matrix;
            return;
        }// end function

        public function FindEdges() : void
        {
            this.matrix = [0, 1, 0, 1, -4, 1, 0, 1, 0];
            this.cf.matrixX = 3;
            this.cf.matrixY = 3;
            this.cf.divisor = 1;
            this.cf.matrix = this.matrix;
            return;
        }// end function

        public function get filter() : ConvolutionFilter
        {
            return this.cf;
        }// end function

    }
}
